// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, sort_child_properties_last
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:junyeyishu/ui/login/QGLoginPasswordPage.dart';
import 'package:junyeyishu/ui/login/QGCodeLoginPage.dart';

import "package:junyeyishu/utils/utils.dart";
import 'package:junyeyishu/widgets/QGWidget.dart';

class QGLoginPage extends StatefulWidget {
  const QGLoginPage({super.key});
  @override
  State<QGLoginPage> createState() => _QGLoginPageState();
}

class _QGLoginPageState extends State<QGLoginPage> {
  int type = 0;
  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        unfocus(context);
      },
      child: Scaffold(
        backgroundColor: Color(0xFFFFFFFF),
        body: Stack(
          children: [
           buildBg(),
            SingleChildScrollView(
              child: Column(
                children: [
                  SizedBox(height: 205.rpx + max(20, kSafeTop)),
                  // buildLogo(),
                  buildContent(),
                  SizedBox(height: 20.rpx),
                  buildBottom(),
                  SizedBox(height: 30.rpx),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  buildBg() {
    return QGImage(asset: "login_bg", width: kScreenWidth);
  }


  buildContent() {
    if (type == 1) {
      return Container(
        child: QGLoginPasswordPage(),
      );
    } else {
      return Container(
        child: QGCodeLoginPage(),
      );
    }
  }

  buildBottom() {
    return Column(
      children: [
        // buildTypeLine(),
        // SizedBox(height: 20.rpx),
        buildSwitchType(),
      ],
    );
  }

  buildTypeLine() {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        SizedBox(width: 25.rpx),
        Container(width: 98.rpx, height: 0.5.rpx, color: Color(0xFFEAEAEA)),
        Container(width: 98.rpx, height: 0.5.rpx, color: Color(0xFFEAEAEA)),
        SizedBox(width: 25.rpx),
      ],
    );
  }

  buildSwitchType() {
    if (type == 0) {
      return Container(
          child: buildSwitch(92.rpx, "已有账号？前往密码登录", "mine_password", toPhoneLogin));
    } else {
      return Container(
          child: buildSwitch(104.rpx, "手机号验证码登录", "mine_phone", toPasswordLogin));
    }
  }

  buildSwitch(width, text, image, VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: 28.rpx,
        alignment: Alignment.center,
        decoration: BoxDecoration(
          
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(width: 3.rpx),
            Text(text,
                style: TextStyle(
                    fontSize: 12.rpx,
                    fontWeight: FontWeight.normal,
                    color: Color(0xFF111111))),
          ],
        ),
      ),
    );
  }

  toPhoneLogin() {
    type = 1;
    if (mounted) {
      setState(() {});
    }
  }

  toPasswordLogin() {
    type = 0;
    if (mounted) {
      setState(() {});
    }
  }
}
